﻿using System;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace GraphDrawing2.Core
{
    public struct DrawContextState : IDisposable
    {
        readonly Graphics g;
        readonly GraphicsState state;

        public DrawContextState(Graphics g)
            : this()
        {
            this.g = g;
            state = g.Save();
        }

        public void Dispose()
        {
            g.Restore(state);
        }
    }

    public static class DrawContextExt
    {
        public static DrawContextState DrawLocal(this Graphics g)
        {
            return new DrawContextState(g);
        }
    }
}